package com.jeff.penny.descriptor;

import java.util.Properties;

public class XmlFactory
{
  public String servletDefinition(String name, String clazz)
  {
    return servletDefinition(name, clazz, null);
  }

  public String servletDefinition(
      String name, String clazz, Properties initParams)
  {
    StringBuffer buffer = new StringBuffer();

    buffer.append("<servlet>");
    buffer.append("<servlet-name>" + name + "</servlet-name>");
    buffer.append("<servlet-class>" + clazz + "</servlet-class>");

    if (initParams != null && initParams.size() > 0)
    {
      for (Object key : initParams.keySet())
      {
        buffer.append("<init-param>");
        buffer.append("<param-name>" + key + "</param-name>");
        buffer.append("<param-value>"
            + initParams.getProperty(key.toString()) + "</param-value>");
        buffer.append("</init-param>");
      }
    }

    buffer.append("</servlet>");

    return buffer.toString();
  }
}
